package time;

import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjusters;

/**
 * 时间校正器
 */
public class TemporalAdjusterTest {
    public static void main(String[] args) {
        method1();
        method2();
    }

    private static void method2() {
        LocalDateTime now = LocalDateTime.now();
        // 将日期调整为下个月的第一天,自定义
        LocalDateTime dateTime = now.with(temporal -> ((LocalDateTime) temporal).plusMonths(1).withDayOfMonth(1));
        System.out.println("now = " + now);
        System.out.println("dateTime = " + dateTime);
    }

    private static void method1() {
        LocalDateTime now = LocalDateTime.now();
        // 将日期调整为下一年的第一个月,采用JKD自带方式
        LocalDateTime dateTime = now.with(TemporalAdjusters.firstDayOfNextYear());
        System.out.println("now = " + now);
        System.out.println("dateTime = " + dateTime);
    }
}
